package cn.kgc.controller;

import cn.kgc.entity.User;
import cn.kgc.service.UserService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className UserController
 * @Date 2018/9/1215:23
 * @Author 韩宏伟
 **/
@Api(description = "用户管理")
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "查找所有用户",produces = "application/json",notes = "状态码：100001：获取信息成功\r\n"+
            "100000 访问成功，但未拿到任何数据",response = Object.class,httpMethod = "post")
    @RequestMapping(value = "/queryAll",produces = "application/json",method = RequestMethod.POST)
    @ResponseBody
    public Object queryAll(){
        JSONObject jsonObject = new JSONObject();
        List<User> userList = userService.queryAll();
        String data = "";//返回的数据
        String message = "";//返回的信息
        String stateCode = "";//状态码
        if (userList!=null){
            data = userList.toString();
            stateCode = "100001";
            message = "访问成功并成功的拿到数据";
        }else{
            data = "";
            stateCode = "100000";
            message= "访问成功，但没拿到数据";
        }
        jsonObject.put("data",data);
        jsonObject.put("message",message);
        jsonObject.put("stateCode",stateCode);
        return jsonObject.toString();
    }
}
